package cn.aylog.pojo;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.lang.reflect.Field;

@Getter
@Setter
@NoArgsConstructor
public class Employee {
    private Integer id;
    private String name;
    private String phone;
    private Integer gender;

    public Employee(Integer id, String name, String phone, Integer gender) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", phone='" + phone + '\'' +
                ", gender=" + gender +
                '}';
    }

    /**
     * 属性赋值
     * @param employee
     */
    public void clone(Employee employee) {
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            try {
                Object o = field.get(employee);
                if (!field.getName().equals("id") && o != null) {
                    field.set(this, o);
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}